<template>
  <div>
    <el-form  label-width="80px" :model="loginForm">
      <el-row>
        <el-col :span="12">
          <el-form-item label="用户名">
            <el-input v-model="loginForm.name" placeholder="请输入用户名"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="密码">
            <el-input v-model="loginForm.password" type="password" placeholder="请输入密码"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item>
        <el-button type="primary" @click="submitForm()">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
  import axios from 'axios'
  export default {
    data() {
      return {
        loginForm: {
          name: '',
          password: ''
        }
      };
    },
    methods: {
      submitForm() {
        axios.post('/api/login', {
          name: this.loginForm.name,
          password: this.loginForm.password,
        }).then(res => {
          console.log(res)
          if (res.data.code === 1) { // 登录成功
          // $router // 路由的实例，控制路由的跳转
          // $route // 当前路由的信息
            this.$router.push('/member/list')
          } else {
            alert('账号或者密码不正确')
          }
        })
      }
    }
  }
</script>